<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    </head>
    <body>
        <?php
        require 'connect.inc';
        require 'session.inc';
        $res = "";
        $state = 0;
        $result;
        $res .=
                "<table width='100%' border='1' cellspacing='0'>
            <tbody>
                <tr></tr>
                <tr>
                    <td>
                        <img src='logo.jpg'>
                    </td>
                    <td>
                        <h1>Photo Album Website</h1>
                    </td>
                </tr>
                <tr>
                    <td width='20%' valign='top'>
                        <a href='index.php'>Home</a>
                        <br>
                        <a href='my_albums.php'>My Albums</a>
                        <br>
                        <a href='users.php'>Other persons</a>
                    </td>";

        $res .= " <td>
                        Users:
                    <br>";
        $strSQL = "SELECT * FROM users";
        $result = mysql_query($strSQL);
        $stt =0;
        if ($result) {
            while ($row = mysql_fetch_array($result)) {
                $stt++;
                $iduser = $row["user_id"];
                $avatar = $row["avatar"];
                $name = $row["full_name"];
                $res .= "<table style='float:left;'>
                        <tbody>
                            <tr>
                                <td>
                                    <img height='100' src='./upload/$iduser/avatar/$avatar'>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <a href='view_user.php?user_id=$iduser'>$name</a>
                                </td>
                            </tr>
                        </tbody>
                    </table>";
            }
            
        }
        $res .= "<br/><br/><br/><br/><br/><br/><br/>
            <hr>
                    Public albums:
                <br>";
        $strSQL = "SELECT a.`album_id`, a.`album_name`, a.`avatar`,u.user_id
                    FROM `album` a, users u 
                    WHERE a.`owner` = u.user_id and `public` = 1";
        $result = mysql_query($strSQL);
        if ($result) {
            while ($row = mysql_fetch_array($result)) {
                $idAlbum = $row["album_id"];
                $idUser = $row["user_id"];
                $avatar = $row["avatar"];
                $name = $row["album_name"];
                $res .= "<table style='float:left;'>
                        <tbody>
                            <tr>
                                <td>
                                    <img height='100' src='./upload/$idUser/$idAlbum/avatar/$avatar'>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <a href='view_album.php?user_id=$idUser&album_id=$idAlbum'>$name</a>
                                </td>
                            </tr>
                        </tbody>
                    </table>";
            }
        }
        // User logged in

        $res .= " <td width='20%' valign='top'>";
        if ($_SESSION["isLogin"] == 1) {
            $res .= "Wellcom <a href='#'>" . $_SESSION["username"] . "</a>!
                |
                <a href='logout.php'>Logout</a>";
        } else {
            $res .= "<a href='login.php'>Login</a>
                    <a href='register.php'>Register</a>
                </td>";
        }
        $res.="</td>
        </tr>
    </tbody>
    </table>";

        echo $res;
        ?>
    </body>

</html>
